class ProposalsController < ApplicationController
  # GET /propostas
  # GET /propostas.xml
#  before_filter :load_forum
#  
#  def load_forum
#    @forum = Forum.find(params[:forum_id])
#  end
  
  
  def index
    @proposals = Proposal.find(:all, :order => "title")

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @proposals }
    end
  end

  # GET /topics/1
  # GET /topics/1.xml
  def show
    @proposal = Proposal.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @proposal }
    end
  end

  # GET /topics/new
  # GET /topics/new.xml
  def new
    @proposal = Proposal.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @proposal }
    end
  end

  # GET /topics/1/edit
  def edit
    @proposal = Proposal.find(params[:id])
  end

  # POST /topics
  # POST /topics.xml
  def create
    @proposal = Proposal.new(params[:proposal])

    respond_to do |format|
      if @proposal.save
        flash[:notice] = 'La tua proposta è stata inserita.'
        format.html { redirect_to(proposals_url) }
        format.xml  { render :xml => @proposal, :status => :created, :location => @proposal }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @proposal.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /topics/1
  # PUT /topics/1.xml
  def update
    @proposal = Proposal.find(params[:id])

    respond_to do |format|
      if @proposal.update_attributes(params[:proposal])
        flash[:notice] = 'Proposta aggiornata correttamente.'
        format.html { redirect_to(proposals_url) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @proposal.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /topics/1
  # DELETE /topics/1.xml
  def destroy
    @proposal = Proposal.find(params[:id])
    @proposal.destroy

    respond_to do |format|
      format.html { redirect_to(proposals_url) }
      format.xml  { head :ok }
    end
  end
end
